package org.custom.spring.boot.security.entity;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.custom.spring.boot.security.interfaces.AuthenToken;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication;

import javax.validation.constraints.NotEmpty;

/**
 * 用户登录实体类
 *
 * @author LiKun
 * @date 2021/11/8 21:29
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@ApiModel("系统登陆实体类")
public class Login implements AuthenToken {
    @NotEmpty(message = "账号名称不能为空")
    @ApiModelProperty(value = "username", notes = "账号名称")
    private String username;

    @NotEmpty(message = "账号密码不能为空")
    @ApiModelProperty(value = "password", notes = "账号密码")
    private String password;

    @ApiModelProperty(value = "rememberMe", notes = "是否自动登录")
    private boolean rememberMe;

    /**
     * 获取认证相关数据
     *
     * @return 认证数据
     */
    @Override
    public final Authentication getAuthentication() {
        return new UsernamePasswordAuthenticationToken(this.username, this.password);
    }
}
